package com.tobehonor.kafkademo.controller;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/kafka")
public class KafkaController {
    
    @Resource
    private KafkaTemplate<String, Object> kafkaTemplate;
    
    @GetMapping("/normalMessage/{message}")
    public ResponseEntity<String> sendNormalMessage(@PathVariable("message") String message) {
        kafkaTemplate.send("sub_topic", message);
        return ResponseEntity.ok("消息发送成功");
    }
}
